package org.water.garden.view;

import org.water.garden.R;

import android.content.Context;
import android.database.Cursor;
import android.provider.Im.Account;
import android.provider.Im.Provider;
import android.view.View;
import android.widget.ResourceCursorAdapter;
import android.widget.TextView;

public class AccountListAdapter extends ResourceCursorAdapter {

	public AccountListAdapter(Context context, Cursor c) {
		super(context, R.layout.account_list_row, c);
	}

	@Override
	public void bindView(View view, Context context, Cursor cursor) {
		//Account name text view
		String accName = cursor.getString(cursor.getColumnIndex(Account.NAME));
		((TextView)view.findViewById(android.R.id.text1)).setText(accName);
		
		//Provider name text view
		int pid = cursor.getInt(cursor.getColumnIndex(Account.PROVIDER));
		Cursor pcur = context.getContentResolver().query(Provider.CONTENT_URI, new String[]{
			Provider.NAME, Provider.FULLNAME}, "_id=?", new String[]{Integer.toString(pid)}, null);
		if(pcur.first()){
			((TextView)view.findViewById(android.R.id.text2)).setText(pcur.getString(1));
		}
		pcur.close();
	}
}